<template>
  <div class="execution">
    <basic-container>
      <avue-crud
        v-bind="bindVal"
        v-on="onEvent"
        :page.sync="page"
        :permission="permissionList"
      >
        <template slot="menu" slot-scope="scope">
          <el-button
            icon="el-icon-edit"
            size="mini"
            type="text"
            v-if="editIsVis(scope.row)"
            @click="myEdit(scope.row)"
            >编辑</el-button
          >
          <el-button
            icon="el-icon-edit"
            size="mini"
            type="text"
            v-if="editIsViss(scope.row)"
            @click="mergeEdit(scope.row)"
            >编辑</el-button
          >
          <el-button
            type="text"
            size="mini"
            icon="el-icon-view"
            @click="myView(scope.row)"
            >预览</el-button
          >
          <el-button
            type="text"
            size="mini"
            icon="el-icon-check"
            @click="openPastRecords(scope.row)"
            >查看历史记录</el-button
          >
        </template>
        <template slot="menuLeft">
          <el-button type="primary" size="small" @click="myAdd"
            >添 加</el-button
          >
          <el-button
            type="primary"
            size="small"
            @click="submitObj"
            v-if="false"
            >提 交</el-button
          >
          <el-button type="primary" size="small" @click="delsObj"
            >删 除</el-button
          >
          <el-button type="primary" size="small" v-if="false" @click="handleExport"
            >导 出</el-button
          >
          <el-button type="primary" size="mini" @click="submitData">加入报表差错</el-button>
        </template>
      </avue-crud>
      <open-dialog
        :DialogVisible.sync="addVisableDialog"
        title="新增"
        width="90%"
      >
        <el-form label-width="60px">
          <avue-form
            ref="formAdd"
            v-model="formAdd.marketingTicket"
            :option="formOption"
            style="margin-bottom:40px;"
          ></avue-form>
          <!-- <dynamic-crud
            title="线下正常售卖(售票员)"
            :data="tableDataOffine"
            :option="tableOptionOffine"
            :spanMethod="rowCountLine"
            :rowAdd="rowAdd"
          ></dynamic-crud> -->
          <dynamic-crud
            title="转账/线下核销明细"
            :data="tableDataOffineTicket"
            :option="tableOptionOffineTicket"
            :spanMethod="rowCountOffineTicket"
            :rowAdd="rowAdd"
          ></dynamic-crud>
          <dynamic-crud
            title="团购售卖"
            :data="tableDataGroup"
            :option="tableOptionGroup"
            :spanMethod="rowCountGroup"
            :rowAdd="rowAdd"
          ></dynamic-crud>
          <div class="bottom-menu">
            <el-button type="primary" @click="save">保存</el-button>
            <el-button type="primary" @click="addVisableDialog = false"
              >取消</el-button
            >
          </div>
        </el-form>
      </open-dialog>

      <open-dialog
        :DialogVisible.sync="editVisableDialog"
        title="编辑"
        width="80%"
      >
        <el-form label-width="60px">
          <avue-form
            ref="formAdd"
            v-model="formAdd.marketingTicket"
            :option="formOption"
          ></avue-form>
          <!-- <dynamic-crud
            title="线下正常售卖(售票员)"
            :data="tableDataOffine"
            :option="tableOptionOffine"
          ></dynamic-crud> -->
          <dynamic-crud
            title="转账/线下核销明细"
            :data="tableDataOffineTicket"
            :option="tableOptionOffineTicket"
          ></dynamic-crud>
          <dynamic-crud
            title="团购售卖"
            :data="tableDataGroup"
            :option="tableOptionGroup"
          ></dynamic-crud>
          <div class="bottom-menu">
            <el-button type="primary" @click="edit">保存</el-button>
            <el-button type="primary" @click="editVisableDialog = false"
              >取消</el-button
            >
          </div>
        </el-form>
      </open-dialog>
      <open-dialog
        :DialogVisible.sync="mergeEditVisableDialog"
        title="编辑"
        width="80%"
      >
        <el-form label-width="60px" v-if="mergeEditVisableDialog">
          <avue-form
            ref="formMergeEdit"
            v-model="formMergeEdit.marketingTicket"
            :option="tableOptionMerge"
          ></avue-form>
          <dynamic-crud
            title="转账/线下核销明细"
            :data="tableDataOffineTicket"
            :option="tableOptionOffineTicket"
          ></dynamic-crud>
          <dynamic-crud
            title="团购售卖"
            :data="tableDataGroup"
            :option="tableOptionGroup"
          ></dynamic-crud>
          <div class="bottom-menu">
            <el-button type="primary" @click="mergeEditSubmit">保存</el-button>
            <el-button type="primary" @click="mergeEditVisableDialog = false"
              >取消</el-button
            >
          </div>
        </el-form>
      </open-dialog>

      <open-dialog
        :DialogVisible.sync="viewVisableDialog"
        title="预览"
        width="80%"
      >
        <el-form label-width="40px">
          <avue-form
            v-model="formAdd.marketingTicket"
            :option="formOptionView"
            style="margin-bottom:40px;"
          ></avue-form>
          <div class="header">线下正常售卖(售票员)</div>
          <avue-crud
            :data="tableDataOffine"
            :option="tableOptionOffineView"
          ></avue-crud>
          <div class="header">转账/线下核销明细</div>
          <avue-crud
            :data="tableDataOffineTicket"
            :option="tableOptionOffineTicketView"
          >
            <template slot="receiptFilePath" slot-scope="{ row }">
              <el-link type="primary" :href="row.receiptFilePath">下载</el-link>
            </template>
          </avue-crud>
          <div class="header">团购售卖</div>
          <avue-crud :data="tableDataGroup" :option="tableOptionGroupView">
            <template slot="receiptFilePath" slot-scope="{ row }">
              <el-link
                type="primary"
                v-if="row.receiptFilePath != null"
                :href="row.receiptFilePath"
                >下载</el-link
              >
            </template>
          </avue-crud>
          <div class="bottom-menu">
            <el-button type="primary" @click="viewVisableDialog = false"
              >取消</el-button
            >
          </div>
        </el-form>
      </open-dialog>
      <open-dialog title="历史记录" :DialogVisible.sync="visableDialogRecords">
        <el-form label-width="60px">
          <avue-crud
            :data="tableDataRecords"
            :option="tableOptionRecords"
          >
            <template slot="menu" slot-scope="scope">
              <el-button
                icon="el-icon-check"
                :size="scope.size"
                :type="scope.type"
                @click="openRecordsDetail(scope.row,scope.index)"
                >查看明细记录</el-button
              >
            </template>
          </avue-crud>
          <div class="bottom-menu">
            <el-button type="primary" @click="visableDialogRecords = false"
              >取消</el-button
            >
          </div>
        </el-form>
      </open-dialog>
      <open-dialog
        :DialogVisible.sync="visableDialogRecordsDetail"
        title="历史明细记录"
        width="80%"
      >
        <el-form>
          <div class="header">转账/线下核销明细</div>
          <avue-crud :data="tableDataOffineTicketRecords" :option="tableOptionOffineTicketView">
          </avue-crud>
          <div class="header">团购售卖</div>
          <avue-crud :data="tableDataGroupRecords" :option="tableOptionGroupView">
          </avue-crud>
          <div class="bottom-menu">
            <el-button @click="visableDialogRecordsDetail = false"
              >关闭</el-button
            >
          </div>
        </el-form>
      </open-dialog>
    </basic-container>
    <addReportEditor ref="addReportEditor" @addReportSuccess="getList"></addReportEditor>
  </div>
</template>

<script>
import baseCrud from "@/mixins/base-crud";
import {
  fetchList,
  getObj,
  addObj,
  putObj,
  delObj,
  exportExcel,
  approvalObj,
  delBatch,
  queryPastRecords,
  queryPastRecordsDetail
} from "@/api/subwaystm/swstmarketingticket/swstmarketingticket";
import {
  tableOption,
  formOption,
  formOptionView,
  tableOptionRecords,
  tableOptionMerge
} from "@/const/crud/subwaystm/swstmarketingticket/swstmarketingticket";
import {
  tableOptionGroup,
  tableOptionGroupView
} from "@/const/crud/subwaystm/swstmarketingticket/swstmarketingticketgroupsell";
import { tableOptionOffine,tableOptionOffineView } from "@/const/crud/subwaystm/swstmarketingticket/swstmarketingticketoffinesell";
import {
  tableOptionOffineTicket,
  tableOptionOffineTicketView
} from "@/const/crud/subwaystm/swstmarketingticket/swstmarketingticketoffinetaketicket";
import { mapGetters } from "vuex";
import { dateFormat } from "@/util/date";
import transitUtil from "@/api/subwayRat/transitUtil";
import addReportEditor from '@/views/stationTiecketManager/xianWngCJXXQR/BBCCGG/BBCCGGSQ/Editor';
export default {
  name: "swstmarketingticket",
  mixins: [baseCrud("subwaystm/swstmarketingticket/swstmarketingticket")],
  components: {
    addReportEditor
  },
  data() {
    return {
      visableDialogRecords: false,
      visableDialogRecordsDetail: false,
      tableDataRecords: [],
      recordsId: [],
      tableDataOffineTicketRecords: [],
      tableDataGroupRecords: [],
      tableOptionRecords: tableOptionRecords,
      group: {},
      searchForm: {},
      tableData: [],
      page: {
        total: 0, // 总页数
        currentPage: 1, // 当前页数
        pageSize: 20 // 每页显示多少条
      },
      tableLoading: false,
      tableOption: tableOption,
      tableOptionGroup: tableOptionGroup,
      tableOptionGroupView: tableOptionGroupView,
      tableOptionOffine: tableOptionOffine,
      tableOptionOffineView: tableOptionOffineView,
      tableOptionOffineTicket: tableOptionOffineTicket,
      tableOptionOffineTicketView: tableOptionOffineTicketView,
      formOption: formOption,
      formOptionView: formOptionView,
      addVisableDialog: false,
      editVisableDialog: false,
      viewVisableDialog: false,
      tableDataOffine: [],
      tableDataOffineTicket: [],
      tableDataGroup: [],
      formAdd: {
        marketingTicket: {},
        ticketOffineSells: [],
        ticketOffineTakeTickets: [],
        ticketGroupSells: []
      },
      searchForm:{
        approvalStatus:'0'
      },
      mergeEditVisableDialog: false,
      tableOptionMerge: tableOptionMerge,
      formMergeEdit: {
        marketingTicket: {},
        ticketOffineSells: [],
        ticketOffineTakeTickets: [],
        ticketGroupSells: []
      },
      selectKeys:[]
    };
  },
  mounted: function() {
    this.$nextTick(function() {
      if (this.$route.query.dialogFlag) {
        this.formAdd.marketingTicket.conductorName = this.$route.query.conductorName;
        this.formAdd.marketingTicket.conductorJobNo = this.$route.query.conductorJobNo;
        this.formAdd.marketingTicket.conductorShifts = this.$route.query.conductorShifts;
        this.formAdd.marketingTicket.opertorTime = this.$route.query.settleTime;
        this.formAdd.marketingTicket.deviceOperateNum = this.$route.query.deviceOperateNum;
        this.formAdd.marketingTicket.bomCode = this.$route.query.bomCode;
        this.addVisableDialog = true;
      }
    });
  },
  watch: {
    "formAdd.marketingTicket.conductorName": function() {
      this.formAdd.marketingTicket.conductorJobNo = this.formAdd.marketingTicket.conductorJobNo;
    }
    // tableDataOffine: {
    //   handler(newValue, oldValue) {
    //     console.log(newValue);
    //     for (const item of newValue) {
    //       if (item.ticketPrice) {
    //         item.cashSellAmount = item.ticketPrice * item.cashSellNum;
    //         item.alipaySellAmount = item.ticketPrice * item.alipaySellNum;
    //         item.wechatSellAmount = item.ticketPrice * item.wechatSellNum;
    //       } else {
    //         item.ticketPrice = 0;
    //         item.cashSellAmount = item.ticketPrice * item.cashSellNum;
    //         item.alipaySellAmount = item.ticketPrice * item.alipaySellNum;
    //         item.wechatSellAmount = item.ticketPrice * item.wechatSellNum;
    //       }
    //     }
    //   },
    //   immediate: true,
    //   deep: true
    // },
    // tableDataOffineTicket: {
    //   handler(newValue, oldValue) {
    //     for (const item of newValue) {
    //       if (item.ticketPrice) {
    //         item.sellAmount = item.ticketPrice * item.ticketNum;
    //       } else {
    //         item.ticketPrice = 0;
    //         item.sellAmount = item.ticketPrice * item.ticketNum;
    //       }
    //     }
    //   },
    //   immediate: true,
    //   deep: true
    // },
    // tableDataGroup: {
    //   handler(newValue, oldValue) {
    //     for (const item of newValue) {
    //       item.sellAmount = 0;
    //       item.discountAmount = 0;
    //       if (item.ticketPrice) {
    //         item.sellAmount = item.ticketPrice * item.sellNum;
    //         item.discountAmount =
    //           item.sellAmount * (100 - item.discountRate) * 0.01;
    //       } else {
    //         item.ticketPrice = 0;
    //         item.sellAmount = item.ticketPrice * item.sellNum;
    //         item.discountAmount =
    //           item.sellAmount * (100 - item.discountRate) * 0.01;
    //       }
    //     }
    //   },
    //   immediate: true,
    //   deep: true
    // }
  },
  created() {
    this.otherVueAction();
  },
  computed: {
    ...mapGetters(["permissions"]),
    permissionList() {
      return {
        addBtn: this.vaildData(
          this.permissions.generator_swstmarketingticket_add,
          false
        ),
        delBtn: this.vaildData(
          this.permissions.generator_swstmarketingticket_del,
          false
        ),
        editBtn: this.vaildData(
          this.permissions.generator_swstmarketingticket_edit,
          false
        )
      };
    }
  },
  methods: {
    async submitData() {
      if (this.$refs.crud.tableSelect.length < 1) {
        this.$message.error("请选择数据");
        return false;
      }
      if (this.$refs.crud.tableSelect.length != 1) {
        this.$message.error("只能选择一条数据");
        return false;
      }
      let res = false;
      let ress = false;
      for (const table of this.$refs.crud.tableSelect) {
        if (table.approvalStatus != "1") {
          this.$message.error("请选择已提交的数据");
          return false;
        }else{
          if (table.isAddReprotError == "1") {
            res = await this.$confirm('该数据已加入报表差错，是否重新加入？', '提示', {
              confirmButtonText: '是',
              cancelButtonText: '否',
              type: 'warning'
            });
            if (!res) {
              return;
            }else{
              ress = true;
            }
          }
        }
      }
      if(res==false){
        ress = await this.$confirm("是否加入报表差错", "提示", {
          confirmButtonText: "确认",
          cancelButtonText: "取消",
          type: "warning"
        });
      }
      if (!ress) {
        return;
      }
      this.selectKeys = this.$refs.crud.tableSelect;
      let param={
        dialogTitle: "加入报表差错",
        diffAmountId:this.selectKeys[0].id,
        dataSourceTable:"sw_st_marketing_ticket",
        lineCode:this.selectKeys[0].lineCode,
        stationCode:this.selectKeys[0].stationCode,
        bomCode:this.selectKeys[0].bomCode,
        reprotTime:this.selectKeys[0].opertorTime,
        reportNameId:8,
        deviceNo:this.selectKeys[0].deviceOperateNum,
        settleBeginTime:this.selectKeys[0].opertorTime,
        settleEndTime:this.selectKeys[0].opertorTime,
        userCodes:this.selectKeys[0].conductorJobNo,
        showType:3,
        dataSource:1,
        page:this.page
      };
      this.$refs.addReportEditor.others_report_add_call(param);
    },
    editIsVis(row) {
      if (row.isMerge == '1') {
        return false;
      } else {
        if (row.approvalStatus == 1) {
          return false;
        } else {
          return true;
        }
      }
    },
    editIsViss(row) {
      if (row.isMerge == '0') {
        return false;
      } else {
        if (row.approvalStatus == 1) {
          return false;
        } else {
          return true;
        }
      }
    },
    async queryPastRecords(row){
      let param={};
      let listRecords = [];
      param.id=row.id;
      var that = this
      await queryPastRecords(param)
        .then(res => {
          listRecords = res.data.data;
          for( var item of listRecords){
            this.tableDataRecords.push(item.logInfo);
            this.recordsId.push(item.id);
          }
        })
    },
    openPastRecords(row){
      this.tableDataRecords = [];
      this.queryPastRecords(row);
      this.visableDialogRecords=true;
    },
    async queryPastRecordsDetail(param){
      await queryPastRecordsDetail(param)
        .then(res => {
          console.log("res:"+JSON.stringify(res))
          // const keys = {
          //   "takeTicket": "SW_ST_MARKETING_TICKET_OFFINE_TAKE_TICKET", //线下取票明细
          //   "groupSell": "SW_ST_MARKETING_TICKET_GROUP_SELL" //团购售卖明细
          // };
          this.tableDataOffineTicketRecords = res.data.data.SW_ST_MARKETING_TICKET_OFFINE_TAKE_TICKET;
          this.tableDataGroupRecords = res.data.data.SW_ST_MARKETING_TICKET_GROUP_SELL;
          // let listData = res.data.data;
          // for(var i;i<=listData.length;i++){if(Object.keys(listData[i])==keys.takeTicket){
          //     this.tableDataOffineTicketRecords = Object.value(listData[i]);
          //   }else if(Object.keys(listData[i])==keys.groupSell){
          //     this.tableDataGroupRecords = Object.value(listData[i]);
          //   }
          // }
        })
    },
    openRecordsDetail(row,index){
      let param={};
      for(var i=0;i<this.recordsId.length;i++){
        if(i==index){
          param.id = this.recordsId[i];
          this.queryPastRecordsDetail(param);
        }
      }
      this.visableDialogRecordsDetail=true;
    },
    rowAdd: function(callback) {
      callback({
        sellTime: dateFormat(new Date()).substring(0, 10),
        takeTicketTime: dateFormat(new Date()).substring(0, 10)
      });
    },
    // uploadPreview(file, column) {
    //     console.log(file, column)
    //     this.$message.success('自定义查看方法页面')
    //   },
    rowCountLine({ row, column, rowIndex, columnIndex }) {
      // if (row.cashSellNum == undefined) {
      //   row.cashSellAmount = "";
      // }
      // if (row.alipaySellNum == undefined) {
      //   row.alipaySellAmount = "";
      // }
      // if (row.wechatSellNum == undefined) {
      //   row.wechatSellAmount = "";
      // }
      // // if(row.cashSellNum ||
      // //    row.alipaySellNum ||
      // //    row.wechatSellNum ){
      // //   row.totalSellNum = Number(row.cashSellNum) + Number(row.alipaySellNum) +Number(row.wechatSellNum);
      // // }
      // if (row.cashSellNum) {
      //   row.totalSellNum = Number(row.cashSellNum);
      // }
      // if (row.alipaySellNum) {
      //   row.totalSellNum = Number(row.alipaySellNum);
      // }
      // if (row.wechatSellNum) {
      //   row.totalSellNum = Number(row.wechatSellNum);
      // }
      // if (row.cashSellNum && row.alipaySellNum) {
      //   row.totalSellNum = Number(row.cashSellNum) + Number(row.alipaySellNum);
      // }
      // if (row.cashSellNum && row.wechatSellNum) {
      //   row.totalSellNum = Number(row.cashSellNum) + Number(row.wechatSellNum);
      // }
      // if (row.alipaySellNum && row.wechatSellNum) {
      //   row.totalSellNum =
      //     Number(row.alipaySellNum) + Number(row.wechatSellNum);
      // }
      // if (row.cashSellNum && row.alipaySellNum && row.wechatSellNum) {
      //   row.totalSellNum =
      //     Number(row.cashSellNum) +
      //     Number(row.alipaySellNum) +
      //     Number(row.wechatSellNum);
      // }
      // if (row.cashSellNum && row.alipaySellNum && row.wechatSellNum) {
      //   row.totalSellNum =
      //     Number(row.cashSellNum) +
      //     Number(row.alipaySellNum) +
      //     Number(row.wechatSellNum);
      // }
      // if (
      //   row.cashSellNum == 0 &&
      //   row.alipaySellNum == 0 &&
      //   row.wechatSellNum == 0
      // ) {
      //   row.totalSellNum = "";
      // }
      // if (
      //   row.cashSellNum == undefined &&
      //   row.alipaySellNum == undefined &&
      //   row.wechatSellNum == undefined
      // ) {
      //   row.totalSellNum = "";
      // }
      // if (row.alipaySellAmount || row.cashSellAmount || row.wechatSellAmount) {
      //   row.totalSellAmount =
      //     Number(row.alipaySellAmount) +
      //     Number(row.cashSellAmount) +
      //     Number(row.wechatSellAmount);
      // } else {
      //   row.totalSellAmount = "";
      // }
    },
    rowCountGroup({ row, column, rowIndex, columnIndex }) {
      if (row.sellNum == undefined) {
        (row.sellAmount = ""), (row.discountAmount = "");
      }
      if (row.discountRate == undefined) {
        row.discountAmount = "";
      }
    },
    rowCountOffineTicket({ row, column, rowIndex, columnIndex }) {
      if (row.ticketNum == undefined) {
        row.sellAmount = "";
      }
    },
    submitObj: function() {
      if (this.$refs.crud.tableSelect.length < 1) {
        this.$message.info("请选择要提交的记录");
        return false;
      }
      let ids = [];
      for (const table of this.$refs.crud.tableSelect) {
        if (table.approvalStatus != "0") {
          this.$message.error("请选择未提交的数据");
          return false;
        }
        ids.push(table.id);
      }
      approvalObj({
        ids: ids.join(","),
        status: "1"
      })
        .then(data => {
          this.$message.success("提交成功");
          this.getList(this.page);
          done();
        })
        .catch(() => {
          loading();
        });
    },
    delsObj: function() {
      if (this.$refs.crud.tableSelect.length < 1) {
        this.$message.info("请选择数据");
        return false;
      }
      let ids = [];
      for (const table of this.$refs.crud.tableSelect) {
        if (table.approvalStatus != "0") {
          this.$message.error("请选择未提交的数据");
          return false;
        }
        if (table.reportModifyStatus == "1") {
          this.$message.error("报表修改状态为“是”的情况下，不允许删除数据");
          return false;
        }
        ids.push(table.id);
      }
      this.$confirm("确认删除?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        delBatch(ids)
          .then(data => {
            this.$message.success("删除成功");
            this.getList(this.page);
            done();
          })
          .catch(() => {
            loading();
          });
      });
    },
    save: function() {
      //this.formAdd.ticketOffineSells = this.tableDataOffine;
      this.formAdd.ticketOffineTakeTickets = this.tableDataOffineTicket;
      this.formAdd.ticketGroupSells = this.tableDataGroup;
      var list = this.formAdd.marketingTicket;
      this.$refs.formAdd.validate(vaild=>{
        if(vaild){
          if (
            this.formAdd.ticketOffineTakeTickets.length == 0 &&
            this.formAdd.ticketGroupSells.length == 0
          ) {
            this.$message.info(
              "请添加线下取票明细或团购售卖信息！"
            );
            return;
          }
          // if (this.formAdd.ticketOffineSells.length != 0) {
          //   for (const item of this.formAdd.ticketOffineSells) {
          //     if (item.ticketName == null || item.sellTime == null) {
          //       this.$message.info(
          //         "线下正常售卖模块车票名称、日期为必填项，不能为空！"
          //       );
          //       return;
          //     }
          //     if (
          //       item.cashSellNum == null &&
          //       item.alipaySellNum == null &&
          //       item.wechatSellNum == null
          //     ) {
          //       this.$message.info(
          //         "线下正常售卖模块现金售卖张数、支付宝售卖张数、微信售卖张数至少填写一个！"
          //       );
          //       return;
          //     }
          //   }
          // }

          if (this.formAdd.ticketOffineTakeTickets.length != 0) {
            for (const item of this.formAdd.ticketOffineTakeTickets) {
              if (
                item.ticketName == null ||
                item.ticketNum == null ||
                item.takeTicketWay == null ||
                item.takeTicketTime == null
              ) {
                this.$message.info(
                  "转账/线下核销明细模块车票名称、售卖张数、取票方式、日期为必填项，不能为空！"
                );
                return;
              }
            }
          }

          if (this.formAdd.ticketGroupSells.length != 0) {
            for (const item of this.formAdd.ticketGroupSells) {
              if (
                item.ticketName == null ||
                item.payMethod == null ||
                item.sellNum == null ||
                item.discountRate == null ||
                item.sellTime == null
              ) {
                this.$message.info(
                  "团购售卖模块车票名称、支付方式、售卖张数、折扣率、售卖日期为必填项，不能为空！"
                );
                return;
              }
            }
          }
          let now = new Date();
          if (now.getHours() < 6) {
            now.setDate(now.getDate() - 1);
          }
          if(this.formAdd.marketingTicket.opertorTime != dateFormat(now).substring(0, 10)){
            this.$confirm("收益时间不是系统默认时间,是否保存？", "提示", {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "warning"
            }).then(() => {
              addObj(this.formAdd)
                .then(data => {
                  this.$message.success("添加成功");
                  this.getList(this.page);
                  this.addVisableDialog = false;
                  done();
                })
                .catch(() => {});
                })
          } else {
            addObj(this.formAdd)
              .then(data => {
                this.$message.success("添加成功");
                this.getList(this.page);
                this.addVisableDialog = false;
                done();
              })
              .catch(() => {});
          }
        }
      })
    },
    edit: function() {
      //this.formAdd.ticketOffineSells = this.tableDataOffine;
      this.formAdd.ticketOffineTakeTickets = this.tableDataOffineTicket;
      this.formAdd.ticketGroupSells = this.tableDataGroup;
      var list = this.formAdd.marketingTicket;
      this.$refs.formAdd.validate(vaild=>{
        if(vaild){
          //如果报表修改状态为已完成 编辑时不能为null
          if(list.reportModifyStatus == '0'){
            if (
              this.formAdd.ticketOffineTakeTickets.length == 0 &&
              this.formAdd.ticketGroupSells.length == 0
            ) {
              this.$message.info(
                "请添加线下取票明细或团购售卖信息！"
              );
              return;
            }
          }
          // if (this.formAdd.ticketOffineSells.length != 0) {
          //   for (const item of this.formAdd.ticketOffineSells) {
          //     if (item.ticketName == null || item.sellTime == null) {
          //       this.$message.info(
          //         "线下正常售卖模块车票名称、日期为必填项，不能为空！"
          //       );
          //       return;
          //     }
          //     if (
          //       item.cashSellNum == null &&
          //       item.alipaySellNum == null &&
          //       item.wechatSellNum == null
          //     ) {
          //       this.$message.info(
          //         "线下正常售卖模块现金售卖张数、支付宝售卖张数、微信售卖张数至少填写一个！"
          //       );
          //       return;
          //     }
          //   }
          // }

          if (this.formAdd.ticketOffineTakeTickets.length != 0) {
            for (const item of this.formAdd.ticketOffineTakeTickets) {
              if (
                item.ticketName == null ||
                item.takeTicketWay == null ||
                //item.ticketWayNum == null ||
                item.takeTicketTime == null
              ) {
                this.$message.info(
                  "转账/线下核销明细模块车票名称、取票方式、日期为必填项，不能为空！"
                );
                return;
              }
            }
          }

          if (this.formAdd.ticketGroupSells.length != 0) {
            for (const item of this.formAdd.ticketGroupSells) {
              if (
                item.ticketName == null ||
                item.payMethod == null ||
                item.sellNum == null ||
                item.discountAmount == null
              ) {
                this.$message.info(
                  "团购售卖模块车票名称、支付方式、售卖张数、折扣为必填项，不能为空！"
                );
                return;
              }
            }
          }
          putObj(this.formAdd)
            .then(data => {
              this.$message.success("修改成功");
              this.getList(this.page);
              this.editVisableDialog = false;
              done();
            })
            .catch(() => {});
        }
      })
    },
    mergeEditSubmit() {
      this.formMergeEdit.ticketOffineSells = this.tableDataOffine;
      this.formMergeEdit.ticketOffineTakeTickets = this.tableDataOffineTicket;
      this.formMergeEdit.ticketGroupSells = this.tableDataGroup;
      var list = this.formMergeEdit.marketingTicket;
      this.$refs.formMergeEdit.validate(vaild=>{
        if(vaild){
          //如果报表修改状态为已完成 编辑时不能为null
          if(list.reportModifyStatus == '0'){
            if (
              this.formMergeEdit.ticketOffineTakeTickets.length == 0 &&
              this.formMergeEdit.ticketGroupSells.length == 0
            ) {
              this.$message.info(
                "请添加线下取票明细或团购售卖信息！"
              );
              return;
            }
          }
          if (this.formMergeEdit.ticketOffineTakeTickets.length != 0) {
            for (const item of this.formMergeEdit.ticketOffineTakeTickets) {
              if (
                item.ticketName == null ||
                item.takeTicketWay == null ||
                //item.ticketWayNum == null ||
                item.takeTicketTime == null
              ) {
                this.$message.info(
                  "转账/线下核销明细模块车票名称、取票方式、日期为必填项，不能为空！"
                );
                return;
              }
            }
          }

          if (this.formMergeEdit.ticketGroupSells.length != 0) {
            for (const item of this.formMergeEdit.ticketGroupSells) {
              if (
                item.ticketName == null ||
                item.payMethod == null ||
                item.sellNum == null ||
                item.discountAmount == null
              ) {
                this.$message.info(
                  "团购售卖模块车票名称、支付方式、售卖张数、折扣为必填项，不能为空！"
                );
                return;
              }
            }
          }
          putObj(this.formMergeEdit)
            .then(data => {
              this.$message.success("修改成功");
              this.getList(this.page);
              this.mergeEditVisableDialog = false;
              done();
            })
            .catch(() => {});
        }
      })
    },
    myAdd: function() {
      Object.keys(this.formAdd.marketingTicket).forEach(item => {
        this.formAdd.marketingTicket[item] = null;
      });
      //this.tableDataOffine = [];
      this.tableDataOffineTicket = [];
      this.tableDataGroup = [];
      this.addVisableDialog = true;
      let now = new Date();
      if (now.getHours() < 6) {
        now.setDate(now.getDate() - 1);
      }
      this.formAdd.marketingTicket.opertorTime = dateFormat(now).substring(0,10);
    },
    myView: function(row) {
      getObj(row.id)
        .then(response => {
          let res = response.data.data;
          this.tableDataOffine = res.ticketOffineSells || [];
          this.tableDataOffineTicket = res.ticketOffineTakeTickets || [];
          for (const item of this.tableDataOffineTicket) {
            if (item.receiptFilePath != null) {
              item.receiptFilePath = "/admin/sys-file/" + item.receiptFilePath;
            }
          }

          this.tableDataGroup = res.ticketGroupSells || [];
          for (const item of this.tableDataGroup) {
            if (item.receiptFilePath != null) {
              item.receiptFilePath = "/admin/sys-file/" + item.receiptFilePath;
            }
          }
          this.formAdd.marketingTicket = res.marketingTicket;
        })
        .then(() => {
          this.viewVisableDialog = true;
        });
    },
    myEdit: function(row) {
      getObj(row.id)
        .then(response => {
          let res = response.data.data;
          //this.tableDataOffine = res.ticketOffineSells === null ? [] : res.ticketOffineSells;
          this.tableDataOffineTicket =
            res.ticketOffineTakeTickets === null
              ? []
              : res.ticketOffineTakeTickets;
          this.tableDataGroup =
            res.ticketGroupSells === null ? [] : res.ticketGroupSells;

          // for (const item of this.tableDataOffine) {
          //   item.$cellEdit = true;
          // }
          for (const item of this.tableDataOffineTicket) {
            item.$cellEdit = true;
          }
          for (const item of this.tableDataGroup) {
            item.$cellEdit = true;
          }
          this.formAdd.marketingTicket = res.marketingTicket;
        })
        .then(() => {
          this.editVisableDialog = true;
        });
    },
    mergeEdit: function(row) {
      getObj(row.id)
        .then(response => {
          let res = response.data.data;
          this.tableDataOffineTicket =
            res.ticketOffineTakeTickets === null
              ? []
              : res.ticketOffineTakeTickets;
          this.tableDataGroup =
            res.ticketGroupSells === null ? [] : res.ticketGroupSells;
          for (const item of this.tableDataOffineTicket) {
            item.$cellEdit = true;
          }
          for (const item of this.tableDataGroup) {
            item.$cellEdit = true;
          }
          this.formMergeEdit.marketingTicket = res.marketingTicket;
        })
        .then(() => {
          this.mergeEditVisableDialog = true;
        });
    },
    addchangeDialog: function() {
      if (this.addchangeDialogFlag) {
        this.addchangeDialogFlag = false;
      } else {
        this.addchangeDialogFlag = true;
      }
    },
    editchangeDialog: function() {
      if (this.editchangeDialogFlag) {
        this.editchangeDialogFlag = false;
      } else {
        this.editchangeDialogFlag = true;
      }
    },
    viewchangeDialog: function() {
      if (this.viewchangeDialogFlag) {
        this.viewchangeDialogFlag = false;
      } else {
        this.viewchangeDialogFlag = true;
      }
    },
    otherVueAction(){
      transitUtil.$on('updateReport_call_8',(param)=>{
        let p=param;
        // p.lineCode=param.lineCode;
        // p.stationCode=param.stationCode;
        // p.opertorTime=param.reprotTime;
        // p.conductorJobNo=param.stationPersonCode;
        fetchList(p).then(response => {
          this.tableData = response.data.data.records;
          this.page.total = response.data.data.total;
          this.tableLoading = false;
        })
      });
    }
  }
};
</script>
<style lang="scss" scoped>
.header {
  margin: 0 auto;
  width: 99%;
  padding: 5px 10px;
  border: 1px solid #e4e4e4;
  border-bottom: none;
  background-color: #eee;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.bottom-menu {
  margin-top: 58px;
  text-align: center;
}
</style>
